var config = {
    url:'/report/index'
};
var  timeStartDay= dateFormatConversion(new Date(new Date(new Date().toLocaleDateString()).getTime()));
var timeEndDay= dateFormatConversion(new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60*1000-1));

var sendObj = {
    "startTime": timeStartDay,
    "endTime": timeEndDay,
};
_call(config['url'], sendObj, function (res) {
    $('#count1').html(res.body.loginCount)
    $('#count2').html(res.body.userAddCount)
    $('#count3').html(res.body.activeCount)
    $('#count4').html(res.body.shareCount)
    $('#count5').html(res.body.integralCount)
});
$('#orderTime').on('click','b',function () {
    $(this).addClass('active');
    $(this).siblings().removeClass('active');
    var time=$(this).text()
    if(time=='日'){
         sendObj = {
            "startTime": timeStartDay,
            "endTime": timeEndDay,
        };
        _call(config['url'], sendObj, function (res) {
            $('#count1').html(res.body.loginCount)
            $('#count2').html(res.body.userAddCount)
            $('#count3').html(res.body.activeCount)
            $('#count4').html(res.body.shareCount)
            $('#count5').html(res.body.integralCount)
        });
    }else if(time=='周'){
        // 获得本周时间   【周一到当天的时间】
        var year=new Date().getFullYear();
        var month=new Date().getMonth()+1;
        var day=new Date().getDate();
        var     thisWeekStart; //本周周一的时间
        if(new Date().getDay()==0){  //周天的情况；
            thisWeekStart = (new Date(year+'/'+month+'/'+day)).getTime()-((new Date().getDay())+6) * 86400000;
        }else{
            thisWeekStart = (new Date(year+'/'+month+'/'+day)).getTime()-((new Date().getDay())-1) * 86400000;
        }


        var weekStartDate=dateFormatConversion(new Date(thisWeekStart));
        var weekEndDate=dateFormatConversion(new Date());
        var sendObj = {
            "startTime": weekStartDate,
            "endTime": weekEndDate,
        };
        _call(config['url'], sendObj, function (res) {
            $('#count1').html(res.body.loginCount)
            $('#count2').html(res.body.userAddCount)
            $('#count3').html(res.body.activeCount)
            $('#count4').html(res.body.shareCount)
            $('#count5').html(res.body.integralCount)
        });

    }else if(time=='月'){
        //获得本月时间
        var weekEndDate=dateFormatConversion(new Date());
        var currentYear=new Date().getFullYear();
        var currentMonth=new Date().getMonth();
        var monthStartDate= dateFormatConversion(new Date(currentYear,currentMonth,1));
        var monthEndDate=weekEndDate;
        var sendObj = {
            "startTime": monthStartDate,
            "endTime": monthEndDate,
        };
        _call(config['url'], sendObj, function (res) {
            $('#count1').html(res.body.loginCount)
            $('#count2').html(res.body.userAddCount)
            $('#count3').html(res.body.activeCount)
            $('#count4').html(res.body.shareCount)
            $('#count5').html(res.body.integralCount)
        });

    }else if(time=='年'){
        var currentYear=new Date().getFullYear();
        console.log(currentYear)
        var sendObj = {
            "startTime": currentYear+'-01-01'+' '+'00:00:00',
            "endTime": currentYear+'-12-31'+' '+'23:59:59'
        };
        _call(config['url'], sendObj, function (res) {
            $('#count1').html(res.body.loginCount)
            $('#count2').html(res.body.userAddCount)
            $('#count3').html(res.body.activeCount)
            $('#count4').html(res.body.shareCount)
            $('#count5').html(res.body.integralCount)
        });
    }
});


// 获取本月本周
function dateFormatConversion(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
}


$('#byTime').click(function () {
    var sendObj = {
        "startTime": $('#startTime').val(),
        "endTime": $('#endTime').val(),
    };
    _call(config['url'], sendObj, function (res) {
        $('#count1').html(res.body.loginCount)
        $('#count2').html(res.body.userAddCount)
        $('#count3').html(res.body.activeCount)
        $('#count4').html(res.body.shareCount)
        $('#count5').html(res.body.integralCount)
    });
})
